fix(duckdb): use actual DuckDB schema for read provider#650
Merged
ewgenius merged 3 commits intoMay 20, 2026
Conversation
…d.schema DuckDB may silently change types during table creation (e.g. Timestamp(ns, tz) becomes Timestamp(µs, tz) for TIMESTAMPTZ). The read provider must advertise the actual storage types so downstream operators (SortExec, RowConverter) receive batches matching the advertised schema. Query DuckDB via get_schema() after table creation to obtain the true storage schema, consistent with DuckDBTableFactory::table_provider() which already does this correctly. Fixes RowConverter column schema mismatch on ORDER BY with partitioned DuckDB acceleration.
2bb1bce to
4ad04d8
Compare
640ef30 to
4ad04d8
Compare
Address review feedback: read the actual DuckDB schema into the schema variable used by both TableDefinition (write path) and the read provider, rather than only fixing the read provider.
phillipleblanc
approved these changes
May 20, 2026
This was referenced May 20, 2026
ewgenius
added a commit
that referenced
this pull request
May 21, 2026
* fix(duckdb): cast query_arrow results to projected_schema DuckDB's query_arrow ignored the projected_schema parameter, returning batches with DuckDB's native types (e.g. Timestamp(µs)) even when the caller expected different types (e.g. Timestamp(ns)). This caused schema mismatches for downstream operators pushed below SchemaCastScanExec. Cast result batches to projected_schema in the output stream when types differ. Add shared cast_batch_to_schema utility in util/arrow.rs for reuse by other Arrow-native connectors (ADBC, ODBC). * Revert "fix(duckdb): use actual DuckDB schema for read provider (#650)" This reverts commit 040aa83.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
DuckDBTableProviderFactory::create()usescmd.schema(user-facing types) as the read provider schema. DuckDB silently downgrades certain types during table creation (e.g.Timestamp(ns, tz)→Timestamp(µs, tz)forTIMESTAMPTZ). The read provider then advertises the wrong schema while returning batches with actual DuckDB types, causing:This crashes
ORDER BYqueries on partitioned DuckDB-accelerated datasets.Fix
After table creation, query DuckDB for the actual storage schema via
get_schema()and use that for the read provider. This matches the existing pattern inDuckDBTableFactory::table_provider().Test
Added
test_read_provider_schema_reflects_actual_duckdb_typeswhich verifies the read provider advertisesTimestamp(Microsecond, ...)when DuckDB downgrades from the requestedTimestamp(Nanosecond, ...).